package com.iocollege.tinyframe.mapper.system;

import com.iocollege.tinyframe.entity.system.SysUserPost;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 用户与岗位关联表 Mapper 接口
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2021-04-10
 */
public interface SysUserPostMapper extends BaseMapper<SysUserPost> {

    @Update("delete from sys_user_post where user_id=#{userId}")
    void deleteUserPostByUserId(Long userId);

    @Insert("<script>insert into sys_user_post(user_id, post_id) values\n" +
            "\t\t<foreach item=\"item\" index=\"index\" collection=\"list\" separator=\",\">\n" +
            "\t\t\t(#{item.userId},#{item.postId})\n" +
            "\t\t</foreach></script>")
    void batchUserPost(List<SysUserPost> list);

    @Delete("<script>delete from sys_user_post where user_id in\n" +
            " \t\t<foreach collection=\"array\" item=\"userId\" open=\"(\" separator=\",\" close=\")\">\n" +
            " \t\t\t#{userId}\n" +
            "        </foreach> </script>")
    void deleteUserPost(Long[] userIds);
}
